import fetch from '../../utils/fetch';
let base = '/api/group';

export const fetchTree = params => {
    return fetch.get(
        `${base}/tree`, 
        { params: params }
    );
};

export const get = params => {
    return fetch.get(
        `${base}/` + params
    );
};

export const update = params => { 
    return fetch.put(
        `${base}/update`, 
        params.entity
    ).then(res => res.data);
};

export const add = params => {
    return fetch.post(
        `${base}`,
        params
    ).then(res => res.data);
};

export const put = params => {
    return fetch.put(
        `${base}/update`,
        params
    ).then(res => res.data);
};

export const remove = params => {
    return fetch.delete(
        `${base}/` + params,
    ).then(res => res.data);
};

export const getMenuAuthority = params => {
    return fetch.get(
        `${base}/` + params + `/authority/menu`
    )
}

export const getElementAuthority = params => {
    return fetch.get(
        `${base}/` + params + `/authority/element`
    )
}

export const modifyMenuAuthority = params => {
    return fetch.post(
        `${base}/` + params.id + `/authority/menu`,
        {menuTrees : params.menuTrees}
    )
}

export const addElementAuthority = params => {
    return fetch.post(
        `${base}/` + params.id + `/authority/element/add`,
        {
            menuId: params.menuId,
            elementId: params.elementId
        }
    )
}

export const removeElementAuthority = params => {
    return fetch.post(
        `${base}/` + params.id + `/authority/element/remove`,
        {
            menuId: params.menuId,
            elementId: params.elementId
        }
    )
}

export const getUsers = params => {
    return fetch.get(
        `${base}/` + params + `/user`
    )
}

export const modifyUsers = params => {
    return fetch.put(
        `${base}/` + params.id + `/user`,
        params.vals
    )
}

